package com.itheima.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Component
@ControllerAdvice
public class ExceptionAdvice {

   /* @ExceptionHandler
    @ResponseBody
    public String doException(Exception e) {
        return "出错了，请联系管理员";
    }*/


    @ExceptionHandler
    @ResponseBody
    public ModelAndView doException(Exception e) {
        System.out.println("ExceptionAdvice");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("msg","出错了大哥");
        modelAndView.setViewName("error.jsp");
        return modelAndView;
    }

}
